﻿@using TbShop.Web.Helpers
@{
    var moduleName = ViewBag.ModuleName;
    var controllerName = ViewBag.ControllerName as string;
    ViewBag.Title = moduleName ;
    var isDel = true;// AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.DeleteSystemMessage);
    var isEdit = true;// AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.SystemMessageDetail);
}
@Html.AntiForgeryToken()
<div class="panel panel-default">
    <div class="panel-heading">
        <strong>@ViewBag.Title</strong>
    </div>
    <div class="panel-body">
        <table id="list_table"></table>
    </div>
</div>

@section scripts{
    @Styles.Render("~/bundles/editable-table-css")
    @Scripts.Render("~/bundles/editable-table")
    <script type="text/javascript">
    $(function () {
        $('#list_table').bootstrapTable({
            columns: [{
                title: '消息类型',
                field: 'MessageTypeText'
            }, {
                title: '消息内容',
                field: 'Content',
                formatter: function (value, row, index) {
                    return value.length > 80 ? (value.substr(0, 80) + "......" ) : value;
                }
            }, {
                title: '是否已读',
                field: 'IsRead',
                formatter: function (value, row, index) {
                    return value ? "<span style='color:blue;'>已读</span>" : "<span style='color:red;'>未读</span>";
                }
            }, {
                title: '操作',
                field: 'Id',
                formatter: function (value, row, index) {
                    return ('@(isEdit ? "true" : "false")' == 'true' ? '<a data-id="' + value + '" href="javascript:void(0)" onclick="showDetail(' + value + ',' + row.VersionNumber + ')" ><i class="fa fa-eye">查看详情</i><a>&nbsp;&nbsp;' : '')
                        + ('@(isDel ? "true" : "false")' == 'true' ? '<a data-id="' + value + '" href="javascript:void(0)" onclick="deleteData(' + value + ',' + row.VersionNumber + ')"><i class="glyphicon glyphicon-trash">删除</i><a>' : '')
                    ;
                }
            }
            ],
            idField: 'Id',
            pagination: true,
            sidePagination: 'server',
            url: '@Url.Action("GetDataList")',
            queryParamsType: '',
            queryParams: function (params) {
                return params;
            },
            locale: 'zh-CN'
        });
    });
    function deleteData(id, vnum) {
        showConfirm("确认要删除该@(moduleName)？", function () {
            $.ajax({
                url: "@Url.Action("DeleteData")",
                type: "POST",
                data: AntiCSRF({ id: id, versionNumber: vnum }),
                dataType: "JSON",
                success: function (data) {
                    if (data == "1") {
                        window.location.reload();
                    }
                    else if (data == "-1") {
                        show_message('数据已被更改，请刷新后重试！', 'warning');
                    } else {
                        show_message('删除失败', 'warning');
                    }
                }
            });
        }, function () { });
    }
        function showDetail(id, vnum) {
                $.ajax({
                    url: "@Url.Action("showDetail")",
                    type: "POST",
                    data: AntiCSRF({ id: id, versionNumber: vnum }),
                    success: function (data) {
                        if (data == "0") {
                            show_message('无法查看', 'warning');
                        }
                        else if (data == "-1") {
                            show_message('请刷新后重试！', 'warning');
                        } else {
                            showConfirm(data, function () {
                                window.location.reload();
                            });
                        }
                    }
                });
    }
    </script>
}

